package com.romotc.qqrobot.webqq.qqInterfaceCall;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;

import com.romotc.qqrobot.bean.QQLogedin;
import com.romotc.scache.httpreq;
/**
 * 删除好友
 * @author Administrator
 *
 */
public class Delete_friend_InterCall extends QQInterfaceCall {

	public static final String Key_Must_Input_Tuin = "FriendsTuin2BDel";
	public static final String Key_Input_DelType = "FriendsDelType";
	private static final int delType_1 = 1;//单向删除
	private static final int delType_2 = 2;
	@Override
	public String buildReqBody(JSONObject reqDataObj, QQLogedin loginQQ)
			throws Exception {
		StringBuilder bld = new StringBuilder();
		bld.append("tuin=").append(reqDataObj.get(Key_Must_Input_Tuin));
		bld.append("&delType=").append(reqDataObj.optInt(Key_Input_DelType, delType_1));
		bld.append("&vfwebqq=").append(loginQQ.getVfwebqq());
		return bld.toString();
	}

	@Override
	public int getLogLevel() {
		return 1001;
	}

	@Override
	public String getReqUrl(JSONObject reqDataObj, QQLogedin loginQQ)
			throws JSONException {
		return "http://s.web2.qq.com/api/delete_friend";
	}

	@Override
	public int getReq_method() {
		return httpreq.REQUEST_POST;
	}

	@Override
	public boolean hasPreCall(QQLogedin loginQQ, JSONObject reqDataObj) {
		return false;
	}

	@Override
	public ArrayList<String> myReqHeaders(int reqBodyLen, QQLogedin loginQQ,JSONObject reqDataObj) {
		ArrayList<String> s = buildReqHeaders(reqBodyLen, loginQQ,
				"http://s.web2.qq.com/proxy.html?v=20110412001&callback=1&id=2", 
				"s.web2.qq.com", "http://s.web2.qq.com");
		//调用后返回{"retcode":100001}问题
		s.add("Content-Type: application/x-www-form-urlencoded");
		return s;
	}

	@Override
	public JSONObject preCall(QQLogedin loginQQ, JSONObject reqDataObj)
			throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	private static Delete_friend_InterCall instance;
	public static synchronized Delete_friend_InterCall getInstance() {
		if(instance == null)
			instance = new Delete_friend_InterCall();
		return instance;
	}

}
